﻿courting = {
	
	skill = diplomacy
	cooldown = { months = 2 }
	is_secret = no
	uses_agents = no
	power_per_skill_point = 4
	resistance_per_skill_point = 0
	minimum_progress_chance = 20
	
	allow = {
		is_adult = yes
		scope:target = { is_adult = yes }
		scope:target = {
			NOT = { this = scope:owner }
		}
		#Game rules
		OR = {
			scope:target = { is_consort_of = scope:owner } #always allowed
			scope:target = { has_relation_lover = scope:owner } #always allowed
			AND = {
				scope:owner = { mgr_can_seduce = yes }
				#Player still gets penalty, but can seduce anyway
				OR = {
					scope:target = { mgr_can_seduce = yes }
					is_ai = no
				}
			}
		}				
		#Have I been blocked from targeting this character?
		custom_description = { #Permanent
			text = seduce_blocked
			object = scope:target

			NOT = {
				scope:target = {
					has_opinion_modifier = {
						modifier = seduce_permanent_blocker_opinion
						target = scope:owner
					}
				}
			}
		}

		#Time-limited blocker
		custom_description = {
			text = romance_cooldown
			object = scope:target

			NOT = {
				scope:target = {
					has_opinion_modifier = {
						modifier = seduce_regular_cooldown_opinion
						target = scope:owner
					}
				}
			}
		}

		#Have I already successfully romanced this person?
		custom_description = {
			text = romance_success_blocked
			object = scope:target

			NOT = {
				scope:target = {
					has_opinion_modifier = {
						modifier = romance_scheme_courtship_opinion
						target = scope:owner
					}
				}
			}
		}

		#They're not interested
		custom_description = {
			text = no_attraction_due_to_gender
			object = scope:target
			subject = scope:owner
			scope:target = { is_attracted_to_gender_of = scope:owner  }
		}

		#AI blockers
		trigger_if = {
			limit = { is_ai = yes }

			trigger_if = {
				limit = {
					OR = {
						any_spouse = {
							count >= 1
						}
						any_relation = {
							type = lover
							count >= 1
						}
					}
				}
				might_cheat_on_every_partner_trigger = yes
			}

			scope:target = {
				trigger_if = { #So players don't get spammed by AI courting
					limit = {
						is_ai = no
					}
					NOT = {
						any_targeting_scheme = {
							scheme_type = courting
						}
					}
				}
			}
		}
		trigger_if = {
			limit = { is_ai = yes }
			NOT = {
				scope:target = {
					 has_character_flag = courting_cooldown
				}
			}
		}
	}
	
	valid = {
		#HARD-BLOCK: Incest Target is too young
		NOT = { 
			custom_description = { 
				text = SCHEME_SEDUCE_UNWILLING_INCEST_TOO_YOUNG
				object = scope:target
				guaranteed_under_20_incest_rejection_trigger = {
					TARGET = scope:target
					SEDUCER = scope:owner
				}
			}
		}

		#We're already soulmates
		scope:owner = {
			NOT = {
				custom_description = {
					text = "romance_already_soulmate"
					object = scope:target
					has_relation_soulmate = scope:target
				}
			}
		}
		#You've been kicked out of bed
		custom_description = { 
			text = seduce_blocked
			object = scope:target
			NOT = {
				scope:owner = {
					has_character_modifier = rejected_from_marriage_bed_modifier
					is_spouse_of = scope:target 
				}
			}
		}

		# They can't consent
		NOT = { scope:target = { has_trait = intellect_bad_3 } } # Implies a mental development level akin to an average child
		NOT = { scope:target = { has_trait = incapable } } # Bed-ridden at best, but in many cases comatose or in a vegetative state
		
		# One of you is celibate
		NOT = { has_trait = celibate }
		scope:target = { NOT = { has_trait = celibate } }
		
		# One of you is imprisoned
		is_imprisoned = no
		scope:target = {
			is_imprisoned = no
		}

		# You're too far away
		scope:target = {
			OR = {
				exists = location
				in_diplomatic_range = scope:owner
			}
		}
	}

	base_success_chance = {
		base = 0
		#Game rules
		modifier = {
			desc = GAME_RULE_SEDUCTION_MORE_DIFFICULT
			has_game_rule = restricted_seduction
			NOT = { scope:target = { is_consort_of = scope:owner } }
			NOT = { scope:target = { has_relation_lover = scope:owner } }
			scope:target = { mgr_can_seduce = no }
			add = -100
		}
		
		#Gallant
		modifier = {
			desc = "SCHEME_GALLANT_TRAIT"
			scope:owner = { has_trait = gallant }
			add = 30
		}

		#Beauty good
		modifier = {
			desc = "scheme_beauty_good_1"
			scope:owner = { has_trait = beauty_good_1 }
			add = 10
		}
		modifier = {
			desc = "scheme_beauty_good_2"
			scope:owner = { has_trait = beauty_good_2 }
			add = 15
		}
		modifier = {
			desc = "scheme_beauty_good_3"
			scope:owner = { has_trait = beauty_good_3 }
			add = 20
		}

		#Physique good
		modifier = {
			desc = "scheme_physique_good_1"
			scope:owner = { has_trait = physique_good_1 }
			add = 5
		}
		modifier = {
			desc = "scheme_physique_good_2"
			scope:owner = { has_trait = physique_good_2 }
			add = 10
		}
		modifier = {
			desc = "scheme_physique_good_3"
			scope:owner = { has_trait = physique_good_3 }
			add = 15
		}

		#Beauty bad
		modifier = {
			desc = "scheme_beauty_bad_1"
			scope:owner = { has_trait = beauty_bad_1 }
			add = -10
		}
		modifier = {
			desc = "scheme_beauty_bad_2"
			scope:owner = { has_trait = beauty_bad_2 }
			add = -15
		}
		modifier = {
			desc = "scheme_beauty_bad_3"
			scope:owner = { has_trait = beauty_bad_3 }
			add = -20
		}

		#TARGET

		#Opinion of owner
		opinion_modifier = {
			who = scope:target
			opinion_target = scope:owner
			min = -50
			max = 50
			multiplier = 1.5
			step = 5
		}

		#Trait similitarity to owner
		compatibility_modifier = {
			who = scope:target
			compatibility_target = scope:owner
			min = -100
			max = 80
			multiplier = 3
		}

		#Rank tier difference (landed target/target whose liege doesn't care)
		modifier = { #3 or more higher rank
			add = 20
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value >= 3
				}
			}
		}
		modifier = { #2 higher rank
			add = 10
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 2
				}
			}
		}
		modifier = { #1 higher rank
			add = 5
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = 1
				}
			}
		}
		modifier = { #1 lower rank
			add = -5
			desc = "LOWER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = -1
				}
			}
		}
		modifier = { #2 lower rank
			add = -10
			desc = "LOWER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value = -2
				}
			}
		}
		modifier = { #3 or less lower rank
			add = -20
			desc = "LOWER_RANK_THAN_SCHEME_TARGET"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = no
			}
			scope:owner = {
				tier_difference = {
					target = scope:target
					value <= -3
				}
			}
		}

		#Rank tier difference (unlanded character)
		modifier = { #3 or more higher rank
			add = 50
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value >= 3
				}
			}
		}
		modifier = { #2 higher rank
			add = 25
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = 2
				}
			}
		}
		modifier = { #1 higher rank
			add = 10
			desc = "HIGHER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
				NOT = {
					is_theocratic_lessee = yes
				}
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = 1
				}
			}
		}
		modifier = { #1 lower rank
			add = -10
			desc = "LOWER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = -1
				}
			}
		}
		modifier = { #2 lower rank
			add = -25
			desc = "LOWER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value = -2
				}
			}
		}
		modifier = { #3 or less lower rank
			add = -50
			desc = "LOWER_RANK_THAN_SCHEME_TARGET_LIEGE"
			scope:target = {
				personal_scheme_success_compare_target_liege_tier_trigger = yes
			}
			scope:owner = {
				tier_difference = {
					target = scope:target.liege
					value <= -3
				}
			}
		}

		#Religious Heads
		modifier = {
			add = -50
			desc = "SCHEME_VS_RELIGIOUS_HEAD"
			scope:target = {
				faith = scope:owner.faith
				faith = {
					exists = religious_head
					religious_head = {
			 			this = scope:target
			 		}
				}
			}
		}

		#Taboo
		modifier = { #Incest is taboo (norms & consequences)
			add = -25
			desc = SCHEME_SEDUCE_TABOO_INCEST
			scope:target = {
				relation_with_character_is_incestuous_in_my_or_lieges_faith_trigger = { CHARACTER = scope:owner }
			}
			scope:owner = { # The Subtle Desire Perk nullifies this
				NOT = { has_perk = subtle_desire_perk }
			}
		}
		modifier = { #Character is not willing to engage in incest with scope:owner
			add = {
				if = {
					limit = { scope:target = { is_close_family_of = scope:owner } }
					value = -40
				}
				else_if = {
					limit = { scope:target = { is_extended_family_of = scope:owner } }
					value = -15
				}
				if = {
					limit = { scope:target = { is_deviant_trigger = yes } }
					add = 15
				}
			}
			desc = SCHEME_SEDUCE_UNWILLING_INCEST
			scope:target = {
				NOT = {
					is_consort_of = scope:owner
				}
				is_close_or_extended_family_of = scope:owner
				NOR = {
					accepts_incest_with_trigger = { CHARACTER = scope:owner } #100% fine with incest with owner
					scope:owner = { has_perk = subtle_desire_perk }  # The Subtle Desire Perk nullifies this
					guaranteed_under_20_incest_rejection_trigger = { # handled by hard block modifier
						TARGET = scope:target
						SEDUCER = scope:owner
					}
				}
			}
		}
		modifier = { #Sodomy
			add = -20
			desc = SCHEME_SEDUCE_TABOO_SODOMY
			scope:target = {
				relation_with_character_is_sodomy_in_my_or_lieges_faith_trigger = { CHARACTER = scope:owner }
				NOT = { freely_accepts_sodomy_with_trigger = { CHARACTER = scope:owner } }
			}
		}

		# Courtship Perk
		modifier = {
			add = courtship_court_success_chance_bonus_value
			desc = SCHEME_COURTSHIP_PERK
			scope:owner = {
				has_perk = courtship_perk
			}
		}

		# Dynasty Kin Personal Scheme Success Chance on Dynasty Perk
		modifier = {
			add = kin_legacy_4_success_chance
			desc = KIN_LEGACY_DESC
			exists = scope:owner.dynasty
			scope:owner.dynasty = {
				has_dynasty_perk = kin_legacy_4
			}
			scope:target.dynasty = scope:owner.dynasty
		}

		# Thicker Than Water Perk
		modifier = {
			add = thicker_than_water_bonus
			desc = BEFRIEND_THICKER_THAN_WATER_PERK_DESC
			scope:owner = {
				has_perk = thicker_than_water_perk
			}
			scope:target = {
				is_close_or_extended_family_of = scope:owner
			}
		}
	}

	on_ready = {
		scheme_owner = {
			#DISCOVERY ROLL
			save_scope_value_as = {
				name = discovery_chance
				value = {
					value = 100
					subtract = scope:scheme.scheme_secrecy
				}
			}
			random = {
				chance = scope:discovery_chance
				save_scope_value_as = {
					name = scheme_discovered
					value = yes
				}
			}

			#SUCCESS ROLL
			random = {
				chance = scope:scheme.scheme_success_chance

				save_scope_value_as = {
					name = scheme_successful
					value = yes
				}
			}

			#CONTINUE WITH OUTCOME ON_ACTION FOR AI TARGETS
			if = {
				limit = { scope:target = { is_ai = yes } }

				trigger_event = {
					on_action = court_outcome
				}
			}
			#FOR PLAYER CHARACTER, SEND CHOICE EVENT
			else = {
				scope:target = {
					trigger_event = {
						id = court_outcome.0003
					}
				}
			}
		}
	}

	on_start = {
		scheme_owner = {
			trigger_event = court_ongoing.0501
		}
	}


	on_monthly = {
		save_scope_as = scheme
		scheme_owner = { save_scope_as = owner }
		scheme_target = { save_scope_as = target }
		

		#Sending an ongoing event
		if = {
			limit = {
				scheme_owner = {
					is_available = yes
				}
				scheme_target = {
					is_available = yes
				}
				player_target_available_for_personal_scheme_ongoing_events_trigger = {
					OWNER = scope:owner
					TARGET = scope:target
				}
				OR = {
					#Milestone 1 event
					AND = {
						scheme_progress >= 2
						NOT = { exists = var:court_milestone_event }
					}
					#Milestone 2 event
					AND = {
						scheme_progress >= 5
						OR = {
							NOT = { exists = var:court_milestone_event }
							var:court_milestone_event < 2
						}
					}
					#Milestone 3 event
					AND = {
						scheme_progress >= 8
						OR = {
							NOT = { exists = var:court_milestone_event }
							var:court_milestone_event < 3
						}
					}
				}
			}
			#Set a var so we can track which milestone you've had
			if = {
				limit = { NOT = { exists = var:court_milestone_event } }
				set_variable = {
					name = court_milestone_event
					value = 1
				}
			}
			else = {
				change_variable = {
					name = court_milestone_event
					add = 1
				}
			}
			#Trigger event
			scheme_owner = {
				trigger_event = { on_action = court_ongoing }
			}
		}
	}

	on_invalidated = {
		if = {
			limit = {
				scope:target = { is_alive = no }
			}
			scope:owner = {
				send_interface_toast = {
					title = court_scheme_invalidated_title
					left_icon = scope:target
					custom_description_no_bullet = {
						object = scope:target
						text = scheme_target_died
					}
				}
			}
		}
		if = {
			limit = {
				scope:target = { is_imprisoned = yes }
			}
			scope:target.imprisoner = {
				save_scope_as = other_imprisoner
			}
			scope:owner = {
				send_interface_toast = {
					title = court_scheme_invalidated_title
					left_icon = scope:target
					right_icon = scope:other_imprisoner
					custom_description_no_bullet = {
						subject = scope:other_imprisoner
						object = scope:target
						text = scheme_target_imprisoned_by_other
					}
				}
			}
		}
		#I am already their soulmate!
		if = {
			limit = {
				NOT = { scheme_progress = 100 }
				scheme_owner = { has_relation_soulmate = scope:scheme.scheme_target }
			}
			scheme_owner = {
				#trigger_event = seduce_outcome.0004
			}
		}
		else_if = { #fallback invalidation
			limit = {
				OR = {
					#We're already soulmates
					scope:owner = {
						has_relation_soulmate = scope:target
					}

					#You've been kicked out of bed
					scope:owner = {
						has_character_modifier = rejected_from_marriage_bed_modifier
						is_spouse_of = scope:target 
					}
						
					scope:owner = {  has_trait = celibate  }
					scope:target = {  has_trait = celibate }
					
					scope:owner = { is_imprisoned = yes }
					scope:target = { is_imprisoned = yes }

					scope:target = {
						NOR = {
							exists = location
							in_diplomatic_range = scope:owner
						}
					}
				}
			}
			scheme_owner = {
				send_interface_message = {
					type = event_generic_neutral
					title = courting
					left_icon = scope:target
					custom_tooltip = courting_invalid
				}
			}
		}
	}

	success_desc = "COURT_SUCCESS_DESC"
}

#DESIGN NOTES
#Taboo romance schemes: pairings which are considered incestuous/sodomy are allowed and there is no secrecy. However, some events should be blocked or texts altered as to avoid public displays of affection for taboo pairings. Anything in private, or anything that can be seen as being honorable or polite, is fine for everyone.